<?php
/**
*
* @package express
* @version $Id: content.php,v 1.012 2008/03/19 01:47:00 nedka Exp $
* @copyright (c) 2008 nedka (Nguyen Dang Khoa)
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$user->add_lang('mods/express');

// Get pages
$page_basename = request_var('page', '');

// Check our mode...
if (!$page_basename)
{
	trigger_error('NO_MODE');
}

// Set lower for the basename
$page_basename = strtolower($page_basename);

// Update page views
$sql = 'UPDATE ' . EXPRESS_PAGES_TABLE . " SET page_views = page_views + 1 WHERE page_basename = '" . $db->sql_escape(strtoupper($page_basename)) . "'";
$db->sql_query($sql);

// Generates custom page...
$sql = 'SELECT *
	FROM ' . EXPRESS_PAGES_TABLE . "
	WHERE page_basename = '" . $db->sql_escape(strtolower($page_basename)) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

if ($row)
{
	if (!$row['page_custom'])
	{
		// Include language file if needed
		$lang = str_replace('.php', '', $row['language_file']);
		$user->add_lang('mods/custom_pages/' . $lang);

		// Get template file of this page
		$page_filename = $row['template_file'];
	}
	else
	{
		$page_filename = '';
	}

	$page_name = (!empty($user->lang[strtoupper($row['page_name'])])) ? $user->lang[strtoupper($row['page_name'])] : $row['page_name'];
	$page_name_explain = (!empty($user->lang[strtoupper($row['page_name']) . '_EXPLAIN'])) ? $user->lang[strtoupper($row['page_name']) . '_EXPLAIN'] : '';
	$page_custom = ($row['page_custom']) ? true : false;

	$template->assign_vars(array(
		'TITLE'				=> $page_name,
		'EXPLAIN'			=> ($page_name_explain) ? $page_name_explain : '',
		'VIEWS'				=> $row['page_views'],
		'CONTENT'			=> ($row['page_custom']) ? generate_text_for_display($row['page_content'], $row['page_content_uid'], $row['page_content_bitfield'], $row['page_content_options']) : '',
		'TIME'				=> $user->format_date($row['page_time']),
		'EXPRESS_COPYRIGHT'	=> sprintf($user->lang['EXPRESS_COPYRIGHT'], $config['express_copyright']),
	));
}

// Output page
page_header($page_name);

$template->set_filenames(array(
	'body' => ($page_custom) ? 'express_content.html' : 'custom_pages/' . $page_filename)
);

page_footer();

?>